<div class="wrapper">
  <?php $this->partial('Common/mainHeader');?>

  <?php $this->partial('Common/mainSiderbar');?>

  <div class="content-wrapper">
    <section class="content-header">
          <h1>财务<small>中心</small></h1>
      <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-fw fa-home"></i> 首页</a></li>
        <li class="active"> 财务中心</li>
      </ol>
    </section>

    <div class="content">
      <div class="callout callout-info">
        <h4>交易管理</h4>
        <p>店代理和会员可向第三方买卖商品。</p>
      </div>

      <div class="row">
        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="info-box">
            <div class="info-box-icon bg-green"><i class="fa fa-fw fa-bar-chart-o"></i></div>
            <div class="info-box-content">
              <span class="info-box-text">货</span>
              <span class="info-box-number"><?php echo $userWallet -> goods; ?> 件</span>
              <div class="pull-right">
                <button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#goodsPayAgain">重复消费</button>
                <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#goodsSell">卖&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;出</button>
                <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#goodsTransform">互&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;转</button>
              </div>
            </div>
          </div>
        </div>

        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="info-box">
            <div class="info-box-icon bg-red"><i class="fa fa-fw fa-money"></i></div>
            <div class="info-box-content">
              <span class="info-box-text">报单币</span>
              <span class="info-box-number"><?php echo $userWallet -> declaration_coin; ?> 币</span>
              <div class="pull-right">
                <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#declarationCoinTransform">互&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;转</button>
              </div>
            </div>
          </div>
        </div>

        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="info-box">
            <div class="info-box-icon bg-orange"><i class="fa fa-fw fa-credit-card"></i></div>
            <div class="info-box-content">
              <span class="info-box-text">购物券</span>
              <span class="info-box-number"><?php echo $userWallet -> coupon; ?> &yen;</span>
            </div>
          </div>
        </div>

        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="info-box">
            <div class="info-box-icon bg-aqua"><i class="fa fa-fw fa-bullseye"></i></div>
            <div class="info-box-content">
              <span class="info-box-text">激活码</span>
              <span class="info-box-number"><?php echo $userWallet -> activation_code; ?> 个</span>
            </div>
          </div>
        </div>

        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="info-box">
            <div class="info-box-icon bg-purple"><i class="fa fa-fw fa-university"></i></div>
            <div class="info-box-content">
              <span class="info-box-text">旅游积分</span>
              <span class="info-box-number"><?php echo $userWallet -> tourism_integration; ?>  分</span>
            </div>
          </div>
        </div>

        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="info-box">
            <div class="info-box-icon bg-blue"><i class="fa fa-fw fa-link"></i></div>
            <div class="info-box-content">
              <span class="info-box-text">剩余见点奖</span>
              <span class="info-box-number"><?php echo $user['point_award']; ?></span>
            </div>
          </div>
        </div>
      </div>

      <hr />

      <div class="row">
        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="box box-widget widget-user">
            <div class="widget-user-header bg-red"><h3 class="widget-user-username">我的左右区团队</h3></div>
            <div class="widget-user-image"><img class="img-circle" src="/dist/img/user1-128x128.jpg" alt="User Avatar"></div>
            <div class="box-footer">
              <div class="row">
                <div class="col-sm-4 border-right">
                  <div class="description-block">
                    <span class="description-text">左区团队总数</span>
                    <h5 class="description-header"><?php echo $countTeams[1]; ?></h5>
                  </div>
                </div>

                <div class="col-sm-4 border-right">
                  <div class="description-block">
                    <h5 class="description-header">团队总数</h5>
                    <span class="description-text"><?php echo $countTeams[1] + $countTeams[2]; ?></span>
                  </div>
                </div>

                <div class="col-sm-4">
                  <div class="description-block">
                    <span class="description-text">右区团队总数</span>
                    <h5 class="description-header"><?php echo $countTeams[2]; ?></h5>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="box box-widget widget-user">
            <div class="widget-user-header bg-black"><h3 class="widget-user-username">本月总业绩</h3></div>
            <div class="widget-user-image"><img class="img-circle" src="/dist/img/user1-128x128.jpg" alt="User Avatar"></div>
            <div class="box-footer">
              <div class="row">
                <div class="col-sm-4 border-right">
                  <div class="description-block">
                    <h5 class="description-header">本月左区总业绩</h5>
                    <span class="description-text"><?php echo $userAchievement -> month_amount_left; ?></span>
                  </div>
                </div>

                <div class="col-sm-4 border-right">
                  <div class="description-block">
                    <h5 class="description-header">本月总业绩</h5>
                    <span class="description-text"><?php echo $userAchievement -> month_amount_left + $userAchievement -> month_amount_right; ?></span>
                  </div>
                </div>

                <div class="col-sm-4">
                  <div class="description-block">
                    <h5 class="description-header">本月右区总业绩</h5>
                    <span class="description-text"><?php echo $userAchievement -> month_amount_right; ?></span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="box box-widget widget-user">
            <div class="widget-user-header bg-green"><h3 class="widget-user-username">左右区总业绩</h3></div>
            <div class="widget-user-image"><img class="img-circle" src="/dist/img/user1-128x128.jpg" alt="User Avatar"></div>
            <div class="box-footer">
              <div class="row">
                <div class="col-sm-4 border-right">
                  <div class="description-block">
                    <h5 class="description-header">左区总业绩</h5>
                    <span class="description-text"><?php echo $countTeams[1] * $USER_EVERY_ONE_ACHIEVEMENT['value']; ?></span>
                  </div>
                </div>

                <div class="col-sm-4 border-right">
                  <div class="description-block">
                    <h5 class="description-header">个人总业绩</h5>
                    <span class="description-text"><?php echo ($countTeams[1] + $countTeams[2]) * $USER_EVERY_ONE_ACHIEVEMENT['value']; ?></span>
                  </div>
                </div>

                <div class="col-sm-4">
                  <div class="description-block">
                    <h5 class="description-header">右区总业绩</h5>
                    <span class="description-text"><?php echo $countTeams[2] * $USER_EVERY_ONE_ACHIEVEMENT['value']; ?></span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <?php $this->partial('Common/mainFooter');?>
</div>

<?php $getTokenSecurity = $this -> security -> getToken(); ?>

<div class="modal modal-danger fade" id="goodsPayAgain">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">重复消费</h4>
      </div>
      <form action="/user/wallet/goods/repeated" method="post">
        <input type="hidden" name="token" value="<?php echo $getTokenSecurity; ?>" />
        <div class="modal-body">
          <div class="form-group">
            <label class="control-label">您目前货总数量为:<?php echo $userWallet -> goods; ?> 件</label>
          </div>

          <div class="form-group">
            <label class="control-label">重复消费消耗货数量：</label>
            <input type="text" name="amount" class="form-control" value="1600" readonly/>
          </div>

          <div class="form-group">
            <label class="control-label">安全密码：</label>
            <input type="password" name="safe_password" class="form-control" required/>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-outline pull-left" data-dismiss="modal">关闭</button>
          <button type="submit" class="btn btn-outline">提交</button>
        </div>
      </form>
    </div>
  </div>
</div>

<div class="modal modal-success fade" id="goodsSell">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">卖出货</h4>
      </div>
      <form action="/user/wallet/goods/sell" method="post">
        <input type="hidden" name="token" value="<?php echo $getTokenSecurity; ?>" />
        <div class="modal-body">
          <div class="form-group">
            <label class="control-label">您目前货总数量为:<?php echo $userWallet -> goods; ?> 件</label>
          </div>

          <div class="form-group">
            <label class="control-label">卖出货数量 (件):</label>
            <input type="number" name="amount" class="form-control" required/>
          </div>

          <div class="form-group">
            <label class="control-label">安全密码：</label>
            <input type="password" name="safe_password" class="form-control" required/>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-outline pull-left" data-dismiss="modal">关闭</button>
          <button type="submit" class="btn btn-outline">提交</button>
        </div>
      </form>
    </div>
  </div>
</div>

<div class="modal modal-info fade" id="goodsTransform">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">货转出</h4>
      </div>
      <form action="/user/wallet/goods/transfer" method="post">
        <input type="hidden" name="token" value="<?php echo $getTokenSecurity; ?>" />
        <div class="modal-body">
          <div class="form-group">
            <label class="control-label">您目前货总数量为:<?php echo $userWallet -> goods; ?> 件</label>
          </div>

          <div class="form-group">
            <label class="control-label">请选择转账类型:</label>
            <select name="type" class="form-control" required>
              <option value="32">货转出</option>
              <!--<option value="41">货转报单币</option>-->
            </select>
          </div>
          
          <div class="form-group">
            <label class="control-label">转入会员编号:</label>
            <input type="number" name="user_code" class="form-control" required/>
          </div>

          <div class="form-group">
            <label class="control-label">转入会员姓名:</label>
            <input type="text" name="real_name" class="form-control" disabled/>
          </div>

          <div class="form-group">
            <label class="control-label">转账数量:</label>
            <input type="number" name="amount" class="form-control" required/>
          </div>

          <div class="form-group">
            <label class="control-label">安全密码：</label>
            <input type="password" name="safe_password" class="form-control" required/>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-outline pull-left" data-dismiss="modal">关闭</button>
          <button type="submit" class="btn btn-outline">提交</button>
        </div>
      </form>
    </div>
  </div>
</div>

<div class="modal modal-info fade" id="declarationCoinTransform">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">报单币转出</h4>
      </div>
      <form action="/user/wallet/declaration_coin/transfer" method="post">
        <input type="hidden" name="token" value="<?php echo $getTokenSecurity; ?>" />
        <div class="modal-body">
          <div class="form-group">
            <label class="control-label">您目前报单币总数量为:<?php echo $userWallet -> declaration_coin; ?> 币</label>
          </div>

          <div class="form-group">
            <label class="control-label">请选择转账类型:</label>
            <select class="form-control" required>
              <option value="4">报单币转出</option>
            </select>
          </div>

          <div class="form-group">
            <label class="control-label">转入会员编号:</label>
            <input type="number" name="user_code" class="form-control" required/>
          </div>

          <div class="form-group">
            <label class="control-label">转入会员姓名:</label>
            <input type="text" name="real_name" class="form-control" disabled/>
          </div>

          <div class="form-group">
            <label class="control-label">转账数量:</label>
            <input type="number" name="amount" class="form-control" value="" required/>
          </div>

          <div class="form-group">
            <label class="control-label">安全密码：</label>
            <input type="password" name="safe_password" class="form-control" value="" required/>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-outline pull-left" data-dismiss="modal">关闭</button>
          <button type="submit" class="btn btn-outline">提交</button>
        </div>
      </form>
    </div>
  </div>
</div>

<?php $this->partial('Common/mainScript');?>
<script type="text/javascript">
  var realNameInput = $('input[name="real_name"]');

  $('input[name="user_code"]').change(function() {
    var _this = $(this);
    $.getJSON('/user/useUserCodeGetUserName?user_code=' + _this.prop('value')).done(function(result) {
      if(result.code !=0 ) {
        realNameInput.prop('value', result.message);
        return false;
      }
      realNameInput.prop('value', result.data.real_name);
    });
  });
</script>